﻿using NewRetail.Application.Components.Platform.Entity;
using NewRetail.Application.Core;
using System;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace NewRetail.Application.Components.Platform
{
    public interface IPaymentReceiptService : IApplicationService
    {
        Task<PaymentReceipt[]> AttachSuppiler(PaymentReceipt[] data);
    }

    public class PaymentReceiptService : MyApplicationService, IPaymentReceiptService
    {
        private readonly IRepository<PaymentReceipt> paymentReceipts;

        public PaymentReceiptService(IRepository<PaymentReceipt> paymentReceipts)
        {
            this.paymentReceipts = paymentReceipts;
        }

        public async Task<PaymentReceipt[]> AttachSuppiler(PaymentReceipt[] data)
        {
            var db = await this.paymentReceipts.GetDbContextAsync();

            await db.AttachData<Supplier, PaymentReceipt>(data, x => x.supplierID, (m, arr) => m.Supplier = arr.FirstOrDefault());

            return data;
        }

    }
}
